function getUrlParams() {

    var search = window.location.search;
    // 写入数据字典
    var tmparray = search.substr(1, search.length).split("&");
    var paramsArray= new Array;

    if (tmparray != null&&tmparray['0']!='') {
        for (var i = 0; i < tmparray.length; i++) {
            var reg = /[=|^==]/;   // 用=进行拆分，但不包括==
            var set1 = tmparray[i].replace(reg, '&');
            var tmpStr2 = set1.split('&');
            var array = new Array;
            array['name'] =tmpStr2[0];
            array['value'] = tmpStr2[1];
            paramsArray.push(array);



        }
    }
    // 将参数数组进行返回
    return paramsArray;

}

function addQueryParams(name,value) {
    var  url= window.location.href;
    var urlarr=url.split("?");
    var key,
        joinChar ='?',
        arrParams = [],
        strParams = '';
    var params=getUrlParams();
    var tag=0;
    if(params.length == 0){
        arrParams[0]='&' + name + '=' +value;
    }else{
        for (key in params) {

            if(params[key]['name']==name){
                arrParams[arrParams.length] = '&' +params[key]['name'] + '=' +value;
                tag=1;
            }else{
                arrParams[arrParams.length] = '&' + params[key]['name'] + '=' +params[key]['value'];
            }

        }
        if(tag==0){
            arrParams[arrParams.length+1]='&' + name + '=' +value;
        }
    }

    // 去掉第一个'&', 因为有joinChar存在
    strParams = arrParams.join('').substring(1);

    return urlarr[0] + joinChar + strParams;
}

function getUrlParamsnourl(search) {


    // 写入数据字典
    var tmparray = search.split("&");
    var paramsArray= new Array;

    if (tmparray != null&&tmparray['0']!='') {
        for (var i = 0; i < tmparray.length; i++) {
            var reg = /[=|^==]/;   // 用=进行拆分，但不包括==
            var set1 = tmparray[i].replace(reg, '&');
            var tmpStr2 = set1.split('&');
            var array = new Array;
            array['name'] =tmpStr2[0];
            array['value'] = tmpStr2[1];
            paramsArray.push(array);



        }
    }
    // 将参数数组进行返回
    return paramsArray;

}

function addQueryParamsnourl(name,value,url) {

    var urlarr=url.split("?");
    var key,
        joinChar ='?',
        arrParams = [],
        strParams = '';
    if(urlarr.length == 1){
        var params=getUrlParamsnourl("");
    }else{
        var params=getUrlParamsnourl(urlarr[1]);
    }

    var tag=0;
    if(params.length == 0){
        arrParams[0]='&' + name + '=' +value;
    }else{
        for (key in params) {

            if(params[key]['name']==name){
                arrParams[arrParams.length] = '&' +params[key]['name'] + '=' +value;
                tag=1;
            }else{
                arrParams[arrParams.length] = '&' + params[key]['name'] + '=' +params[key]['value'];
            }

        }
        if(tag==0){
            arrParams[arrParams.length+1]='&' + name + '=' +value;
        }
    }

    // 去掉第一个'&', 因为有joinChar存在
    strParams = arrParams.join('').substring(1);
    return urlarr[0] + joinChar + strParams;
}

/*
 * url 目标url
 * arg 需要替换的参数名称
 * arg_val 替换后的参数的值
 * return url 参数替换后的url
 */
function changeURLArg(url,arg,arg_val){
    var pattern=arg+'=([^&]*)';
    var replaceText=arg+'='+arg_val;
    if(url.match(pattern)){
        var tmp='/('+ arg+'=)([^&]*)/gi';
        tmp=url.replace(eval(tmp),replaceText);
        return tmp;
    }else{
        if(url.match('[\?]')){
            return url+'&'+replaceText;
        }else{
            return url+'?'+replaceText;
        }
    }
    return url+'\n'+arg+'\n'+arg_val;
}

function GetRequest(name) {
    var params=getUrlParams();
    for (var i = 0; i < params.length; i++) {
       if(params[i]['name']==name){
           return params[i]['value']
       }
    }
    return false;


}





